package helper.com.utils;

import helper.com.exception.CustomException;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

/**
 * @author 大忽悠
 * @create 2022/5/18 13:37
 */
public class FileUtil {
    public static void inReadToOut(BufferedInputStream in, BufferedOutputStream out) {
        try {
            byte[] bytes = new byte[1024];
            int len=-1;
            while((len= in.read(bytes))!=-1){
                out.write(bytes,0,len);
            }
            out.flush();
        } catch (FileNotFoundException e) {
            throw new CustomException("文件读取失败");
        } catch (IOException e) {
            throw new CustomException("文件读取失败");
        }finally {
            if(out !=null){
                try {
                    out.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if(in !=null){
                try {
                    in.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
